package in.iqing.control.api.callback;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;

import in.iqing.model.bean.RequestResult;

/**
 * Created by ZuoShu on 15/7/7.
 */
public abstract class RequestCallback extends BaseCallback {
    public abstract void onSuccess();

    @Override
    public void onSuccess(String data) {
        if (TextUtils.isEmpty(data)) {
            onFailure(ERROR_CODE_PARSE, "");
        }
        RequestResult result = JSON.parseObject(data, RequestResult.class);
        if (result == null || result.getCode() != 0) {
            onFailure(result.getCode(), "");
        } else {
            onSuccess();
        }
    }

    @Override
    public void onFailure(int code, String msg) {
    }
}
